package com.ellecity06.cwhiskymall.http.interceptor

import com.ellecity06.common.ktx.appVersionName
import com.ellecity06.cwhiskymall.storage.AppStorage
import okhttp3.Interceptor
import okhttp3.Response
import okio.IOException

class CommonHeaderInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        if (AppStorage.token != null && AppStorage.token!!.isNotEmpty()) {
            builder.addHeader("Authorization", "${AppStorage.token}")
        }
        builder.addHeader("version", "v$appVersionName")
        builder.addHeader("platform", "Android")

        return chain.proceed(builder.build())
    }
}